#ifndef __IPC_BRIDGE_MATLAB_NIDAQIO_DOUBLES__
#define __IPC_BRIDGE_MATLAB_NIDAQIO_DOUBLES__
#include <ipc_bridge_matlab/ipc_bridge_matlab.h>
#include <ipc_bridge/msgs/nidaqIO_Doubles.h>

namespace ipc_bridge_matlab
{
  namespace nidaqIO
  {
    namespace Doubles
    {
      static mxArray* ProcessMessage(const ipc_bridge::nidaqIO::Doubles &msg)
      {
        const char *fields[] = {"data"};
        const int nfields = sizeof(fields)/sizeof(*fields);
        mxArray *out = mxCreateStructMatrix(1, 1, nfields, fields);

		mxArray *m = mxCreateDoubleMatrix(1,msg.length,mxREAL);
		memcpy(mxGetPr(m), msg.data, msg.length*sizeof(double));
        
        mxSetField(out, 0, "data", m);

        return out;
      }
    
      static int ProcessArray(const mxArray *a, ipc_bridge::nidaqIO::Doubles &msg)
      {
        mxArray *field;
        
        field = mxGetField(a, 0, "data");
		msg.length = mxGetN(field)*mxGetM(field);
		memcpy(msg.data, mxGetPr(field), sizeof(double)*msg.length);
     
        return SUCCESS;
      }

      static void Cleanup(ipc_bridge::nidaqIO::Doubles &msg)
      {
      }
    }
  }
}
#endif

